	@include('admin.head')
	<link rel="stylesheet" type="text/css" href="<%url('css/compiled/elements.css')%>">
	<style>
	#cover{
		width: 100%;
		height: 100%;
		position: absolute;
		background: rgba(0,0,0,0.5);
		display: none;
		z-index: 100;
	}
	.form_hide{
		position: fixed !important;
		left: 25%;
		top: 10%;
	}
	</style>
	<div class="container">
		<div class="row">
			@include('admin.side')
			<div class="col-md-10" id="content-wrapper">
				<div class="row">
					<div class="col-lg-12">
						<div class="clearfix">
							<h1 class="pull-left">前台基础配置</h1>
						</div>
						<div class="row">
							<div class="col-lg-12">
								<div class="main-box">
									<div class="row cf nestable-lists">
										<div class="col-md-6 dd cate_box" id="" type="domains">
											<h4>领域表 <button type="button" class="btn btn-primary btu_show">添加一级分类</button></h4>
											<ol class="dd-list" id="lingyu">
											</ol>
										</div>
										<div class="col-md-6 dd cate_box" id="" type="techs">
											<h4>节能技术表 <button type="button" class="btn btn-primary btu_show">添加一级分类</button></h4>
											<ol class="dd-list" id="jieneng">
											</ol>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div id="cover">
						<div class="col-lg-6 form_hide">
							<div class="main-box">
								<form role="form">
									<div class="form-group">
										<label for="exampleTextarea">添加多个用 “|”或 回车换行 分隔开</label>
										<textarea class="form-control" id="exampleTextarea" rows="5"></textarea>
									</div>
									<button  type="button" class="btn btn-primary" id="btn_sub">添加</button>
									<button  type="button" class="btn btn-primary btn_cancel">取消</button>
								</form>
							</div>
						</div>
						<style>
						.edit{
							border: none;
							line-height: 24px;
							font-size: 16px;
							background: rgba(255,255,255,0);
						}
						</style>
					</div>
				</div>
			</div>
		</div>
	</div>
	@include("admin.footer")
	@include("admin.common")

</body>
<script type="text/javascript">
	var type = '';
	$('.btu_show').bind('click',function(){
		type = $(this).parents('.cate_box').attr('type');
		$('#cover').show();
	})

	$('.btn_cancel').bind('click',function(){
		type = '';
		$('#exampleTextarea').val('');
		$('#cover').hide();
	})

	$('#btn_sub').bind('click',function(){
		var url = 'frontbase/types'
		var data = $('#exampleTextarea').val();
		$.post(url,{data:data,type:type,pid:pid},function(data){
			if(data.success){
				$('#exampleTextarea').val('');
				window.location.reload();
			}
		})
	})

	$.post('frontbase/domainslist',function(data){
		str = str_list(data);
		$('#lingyu').html(str);
		$.post('frontbase/techslist',function(data){
			str = str_list(data);
			$('#jieneng').html(str);
			bind_e();
		})
	})

	function str_list(data){
		var str = '';
		$.each(data.data,function(k,v){

			if(v.parent_id != 0){
				str += '<li class="dd-item dd-item-list" son="'+v.parent_id+'" style="margin-left:50px;" data-id="13">';
				str += '<div class="dd-handle-list"><i class="fa fa-bars"></i></div>';
				str += '<div class="dd-handle"><input oname="'+v.cate_name+'" nid="'+v.id+'" class="editName" style="border:none;background:rgba(255,255,255,0)" value="'+v.cate_name+'" type="text">';
				str += '<div class="nested-links">';
				str += '<a href="javascript:;" cid="'+v.id+'" class="nested-link btn_delete"><i class="glyphicon glyphicon-minus"></i></a>';
				str += '</div></div></li>';
			}else{
				str += '<li class="dd-item dd-item-list" parent="'+v.id+'" data-id="13">';
				str += '<div class="dd-handle-list"><i class="fa fa-bars"></i></div>';
				str += '<div class="dd-handle"><input oname="'+v.cate_name+'" nid="'+v.id+'" class="editName" style="border:none;background:rgba(255,255,255,0)" value="'+v.cate_name+'" type="text">';
				str += '<div class="nested-links">';
				str += '<a href="javascript:;" pid="'+v.id+'" class="nested-link btu_show"><i class="glyphicon glyphicon-plus"></i></a>';
				str += '<a href="javascript:;" cid="'+v.id+'" class="nested-link btn_delete"><i class="glyphicon glyphicon-minus"></i></a>';
				str += '</div></div></li>';
			}
		})
		return str;
	}

	function bind_e(){

		$('.btu_show').bind('click',function(){
			type = $(this).parents('.cate_box').attr('type');
			pid = $(this).attr('pid');
			$('#cover').show();
		})
		$(".btn_delete").bind('click',function(){
			_this = $(this);
			confirm('','确定要删除吗？','warning',function (data){
				if(data == 1){
					type = _this.parents('.cate_box').attr('type');
					var cid = _this.attr('cid');
					$.post('frontbase/deletetypes',{cid:cid,type:type},function(resp){
						if(resp.success){
							_this.parents('li').remove();
						}else{
							alert(resp);
						}
					})
				}
			})
		})

		$('.editName').bind('blur',function(){
			_this = $(this);
			var id = _this.attr('nid');
			var type = _this.parents('.cate_box').attr('type');
			var oname = $.trim(_this.attr('oname'));
			var name = $.trim(_this.val());
			if(oname == name){
				_this.val(oname);
				return;
			}else{
				$.post('frontbase/edittypes',{id:id,type:type,name:name},function(data){
					if(data.success){
						_this.attr('oname',name);
					}
				})
			}
		})

	}



</script>


</html>